package com.yunshan.mp;

import com.yunshan.common.core.controller.BaseController;
import com.yunshan.common.core.domain.AjaxResult;
import com.yunshan.mp.domain.*;
import com.yunshan.mp.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * 首页列表查询
 * 
 * @author yunshan
 * @date 2025-02-11
 */
@Api(tags = "首页列表查询")
@RestController
@RequestMapping("/api/index")
public class MpIndexController extends BaseController
{
    @Autowired
    private IMpIndexBannerService mpIndexBannerService;
    @Autowired
    private IMpIndexIntroductionService mpIndexIntroductionService;
    @Autowired
    private IMpIndexActivityReviewService mpIndexActivityReviewService;
    @Autowired
    private IMpIndexActivityNoticeService mpIndexActivityNoticeService;
    @Autowired
    private IMpIndexPreviewService mpIndexPreviewService;

    /**
     * 查询预览页
     */
    @ApiOperation("查询预览页")
    @GetMapping("/preview")
    public AjaxResult preview()
    {
        return success(mpIndexPreviewService.selectMpIndexPreview());
    }


    /**
     * 查询活动回顾和会所简介封面
     */
    @ApiOperation("查询首页图片封面")
    @GetMapping("/covers")
    public AjaxResult covers()
    {
        BannerImgVo bannerImgVo = new BannerImgVo();
        //首页banner
        bannerImgVo.setBanner(mpIndexBannerService.selectUniList());
        //活动公告
        bannerImgVo.setActivityNotice(mpIndexActivityNoticeService.selectCoverUniList());
        //活动回顾
        MpIndexActivityReview mpIndexActivityReview = mpIndexActivityReviewService.selectUniInfo();
        if (mpIndexActivityReview != null) {
            bannerImgVo.setActivityReview(mpIndexActivityReview.getCoverImg());
        }
        //会所简介
        MpIndexIntroduction introduction = mpIndexIntroductionService.selectUniInfo();
        if (introduction != null){
            bannerImgVo.setIntroduction(introduction.getCoverImg());
        }
        return success(bannerImgVo);
    }

    /**
     * 获取会所简介详情
     */
    @ApiOperation("会所简介详情")
    @GetMapping("/introduction")
    public AjaxResult introduction()
    {
        MpIndexIntroduction introduction = mpIndexIntroductionService.selectUniInfo();
        if (introduction != null){
            return AjaxResult.success("查询成功", introduction.getPosterImg());
        }
        return success();
    }

    /**
     * 获取活动回顾详情
     */
    @ApiOperation("活动回顾详情")
    @GetMapping("/review")
    public AjaxResult review()
    {
        MpIndexActivityReview mpIndexActivityReview = mpIndexActivityReviewService.selectUniInfo();
        if (mpIndexActivityReview != null) {
            return AjaxResult.success("查询成功", mpIndexActivityReview.getPosterImg());
        }
        return success();
    }

    /**
     * 获取活动公告列表
     */
    @ApiOperation("活动公告列表")
    @GetMapping("/notice")
    public AjaxResult notice()
    {
        List<MpIndexActivityNotice> mpIndexActivityNotice = mpIndexActivityNoticeService.selectNoticeList();
        return success(mpIndexActivityNotice);
    }

    /**
     * 获取活动公告详情
     */
    @ApiOperation("活动公告详情")
    @GetMapping("/noticeInfo")
    public AjaxResult noticeInfo(
            @ApiParam(name = "id", value = "公告id", required = true)
            @RequestParam Long id)
    {
        return success(mpIndexActivityNoticeService.selectMpIndexActivityNoticeById(id));
    }
}
